package com.zy.explore.license.infrastructure.result;

import feign.codec.Decoder;
import feign.optionals.OptionalDecoder;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.boot.autoconfigure.http.HttpMessageConverters;
import org.springframework.cloud.openfeign.support.ResponseEntityDecoder;
import org.springframework.cloud.openfeign.support.SpringDecoder;
import org.springframework.context.annotation.Bean;

/**
 * 对于本地手写 FeignClient 指定默认 Decoder 配置
 *
 * <pre class="code">
 * @FeignClient(value = "my-service", configuration = DisableResultVoDecoder.class, contextId = "AnotherClient")
 * public interface LocalFeign {}
 * </pre>
 * <p>
 * 其中，contextId 用于指定多个自定义配置的 FeignClient 对应同一个 Server，只有一个 FeignClient 可省略
 * <a href="https://github.com/spring-cloud/spring-cloud-openfeign/pull/90">
 *     Support Multiple Clients Using The Same Service </a>
 *
 * @author administrator
 * @see ResultVODecoder
 * @since 2020/8/27
 */
public class DisableResultVODecoder {

    @Bean
    public Decoder decoder(ObjectFactory<HttpMessageConverters> messageConverters) {
        return new OptionalDecoder(new ResponseEntityDecoder(new SpringDecoder(messageConverters)));
    }
}
